package ncme.auto.framework.core.callback;

import ncme.auto.framework.core.annotation.Remind;
import ncme.auto.framework.core.entities.ResMsg;
import ncme.auto.framework.core.entities.aspect.parameter.ServiceInfo;

@Remind("用于无参数实体的controller，返回值添加包装，如果part部分结果不为ResMsg则包装为ResMsg")
public class NoEntityProcessPart {

    private NoEntityProcessInterface getPart = () -> null;

    private NoEntityProcessInterface addPart = () -> null;

    private NoEntityProcessInterface putPart = () -> null;

    private NoEntityProcessInterface delPart = () -> null;

    public void setGetPartCallback(NoEntityProcessInterface getPart) {
        this.getPart = getPart;
    }

    public void setAddPartCallback(NoEntityProcessInterface addPart) {
        this.addPart = addPart;
    }

    public void setPutPartCallback(NoEntityProcessInterface putPart) {
        this.putPart = putPart;
    }

    public void setDelPartCallback(NoEntityProcessInterface delPart) {
        this.delPart = delPart;
    }

    public ResMsg process(ServiceInfo serviceInfo) throws Throwable {
        ResMsg result;
        String requestType = serviceInfo.getRequest().getMethod();
        switch (requestType) {
            case "GET":
                result = this.getPart.onCallBack();
                break;
            case "POST":
                result = this.addPart.onCallBack();
                break;
            case "PUT":
                result = this.putPart.onCallBack();
                break;
            case "DELETE":
                result = this.delPart.onCallBack();
                break;
            default:
                return null;
        }
        return result;
    }

}
